package com.uy.cuantoconocesdeuruguay.utiles;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.json.JSONObject;

public class NetworkUtils {
	public static String getIPAddress() {
		String ip = StringPool.BLANK;
		try {
			HttpClient httpclient = new DefaultHttpClient();
			HttpGet httpget = new HttpGet(StringPool.IP_URL);
			HttpResponse response;
			response = httpclient.execute(httpget);
			HttpEntity entity = response.getEntity();
			entity.getContentLength();
			String str = EntityUtils.toString(entity);
			System.out.println("NetworkUtils: "+str);
			JSONObject json_data = new JSONObject(str);
			ip = json_data.getString(StringPool.IP);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return ip;
	}
}